import mebcouponZQ from '../../views/mall/mebcouponZQ.vue'
let extension = {
  components: {//动态扩充组件或组件路径
    //表单header、content、footer对应位置扩充的组件
    gridHeader: '',//{ template: "<div>扩展组xx件</div>" },
    gridBody: mebcouponZQ,
    gridFooter: '',
    //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
    modelHeader: '',
    modelBody: '',
    modelFooter: ''
  },
  buttons: {
    view: [
      {
        name: "新建",
        icon: 'md-add',
        value: 'XJ',
        class: '',
        type: 'error',
        index: 1,//显示的位置
        onClick: function () {
          this.$refs.gridBody.model = true
          this.$refs.gridBody.title = '新建'
          this.$nextTick(() => {
            this.$refs.gridBody.editFormOptions[0][0] = {
              title: "优惠券模板名称",
              field: "coupon_code",
              type: "select",
              dataKey: '',
              data: this.cardTypeList,
              disabled: false,
              required: true,
            }
            this.$refs.gridBody.$refs.myform.reset()
          })
        }
      },
    ], box: [], detail: []
  },//扩展的按钮
  data () {
    return {
      grantorid: '',
      grantor: '',
      cardmodel: '',
      cardTypeList: []
    }
  },
  methods: {//事件扩展
    getFormOption (field) {
      let option;
      this.editFormOptions.forEach(x => {
        x.forEach(item => {
          if (item.field == field) {
            option = item;
          }
        })
      })
      return option;
    },
    onInit () {
      // 不显示多选框
      //;
      // 显示序号
      //;
      // 开启单选
      //;
      this.$store.getters.data().viewPageTest = this;
      let parmas = {
        order: "desc",
        page: 1,
        rows: 10000,
        sort: "id",
        wheres: "[]"
      }
      this.cardTypeList = []
      this.http.post('/api/MebCoupon/getPageData', parmas).then(res => {
        res.rows.forEach(i => {
          let obj = {
            key: i.code,
            value: i.name
          }
          this.cardTypeList.push(obj)
        })
      })
      this.columns.push({
        title: '操作',
        fixed: 'right',
        width: 200,
        render: (h, { row, column, index }) => {
          return [h(
            "a", {
            style: {},
            on: {
              click: (e) => {
                this.$refs.gridBody.openXQ(row)
              }
            }
          },
            "查看内容"
          ),
          h(
            "a", {
            style: {

            },
            on: {
              click: (e) => {
                this.$refs.gridBody.openQR(row)
              }
            }
          },
            " 查看二维码"
          )
          ]
        }
      })
    },
    rowClick ({ row, column, event }) { //查询界面table点击行选中当前行
      this.$refs.table.$refs.table.toggleRowSelection(row);
      return true;
    },
    searchBefore (param) {
      let wheres = [{
        'name': 'coupon_type',
        'value': '0',
        'displayType': 'text'//设置为模糊查询,其他不需要设置
      }]

      param.wheres.push(...wheres);
      return true
    },
    delBefore (ids, rows) {
      let p = {
        order: "desc",
        page: 1,
        rows: 10000,
        sort: "createtime",
        wheres: `[{\"name\":\"coupon_makeid\",\"value\":\"${rows[0].coupon_makeid}\",\"displayType\":\"text\"}]`
      }
      this.http.post('/api/MebCouponhis/getPageData', p).then(res => {
        if (res.rows.length != 0) {
          this.$Message.error('此优惠券制劵下有优惠券，暂不支持删除')
        } else {
          this.http.post('/api/MebcouponMake/del', [ids.toString()]).then(res => {
            this.refresh()
          })
        }
      })
    },
  }
};
export default extension;
